#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_get_clicked()
{
    // 获取上方按钮对于widget左上角的位置
    QRect rect = ui->pushButton_target->geometry();
    qDebug() << rect;
}

void Widget::on_pushButton_up_clicked()
{
    QRect rect = ui->pushButton_target->geometry();
    qDebug() << "向上走前: " << rect;
//    // 这仅相较于按钮左上角的点
//    rect.setY(rect.y() - 5);
//    ui->pushButton_target->setGeometry(rect);

    // 整体进行平移
    ui->pushButton_target->setGeometry(rect.x(), rect.y() - 5, rect.width(), rect.height());
    qDebug() << "向上走后: " << rect;
}

void Widget::on_pushButton_down_clicked()
{
    QRect rect = ui->pushButton_target->geometry();
    qDebug() << "向下走前: " << rect;
//    // 这仅相较于按钮左上角的点
//    rect.setY(rect.y() + 5);
//    ui->pushButton_target->setGeometry(rect);

    // 整体进行平移
    ui->pushButton_target->setGeometry(rect.x(), rect.y() + 5, rect.width(), rect.height());
    qDebug() << "向下走后: " << rect;
}

void Widget::on_pushButton_left_clicked()
{
    QRect rect = ui->pushButton_target->geometry();
    qDebug() << "向左走前: " << rect;
//    // 这仅相较于按钮左上角的点
//    rect.setX(rect.x() - 5);
//    ui->pushButton_target->setGeometry(rect);

    // 整体进行平移
    ui->pushButton_target->setGeometry(rect.x() - 5, rect.y(), rect.width(), rect.height());
    qDebug() << "向左走后: " << rect;
}

void Widget::on_pushButton_right_clicked()
{
    QRect rect = ui->pushButton_target->geometry();
    qDebug() << "向右走前: " << rect;
//    // 这仅相较于按钮左上角的点
//    rect.setX(rect.x() + 5);
//    ui->pushButton_target->setGeometry(rect);

    // 整体进行平移
    ui->pushButton_target->setGeometry(rect.x() + 5, rect.y(), rect.width(), rect.height());
    qDebug() << "向右走后: " << rect;
}
